package com.zjw.strategy.productStrategyImpl;

import com.zjw.strategy.ProductStrategy;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.math.RoundingMode;


/**
 * 商品打折策略类
 */
@Component
public class Discount4Product implements ProductStrategy {

    //打折力度
    private String discount = "0.8";



    @Override
    public double calPrice(String num, String price) {
        BigDecimal bigDecimalPrice = new BigDecimal(price);
        BigDecimal bigDecimalNum = new BigDecimal(num);
        BigDecimal bigDecimalDiscount = new BigDecimal(discount);
        return bigDecimalPrice.multiply(bigDecimalNum).multiply(bigDecimalDiscount).
                setScale(2, RoundingMode.HALF_UP).doubleValue();

    }
}
